<?php
session_save_path('sessions');
session_start();

// Include the different user types so we can filter out unauthorized users
include("include/dbUserTypes.php");

// Include our user class
include_once("include/user.php");

// Create a variable to store our user if we're validated
$user = null;

// Check if we're in a valid session. If not, go back to main login page.
if( !isset($_SESSION['user']) || $_SESSION['user'] == null ) {
    header("location:main_login.php");
}
else {
    // Unserialize our user to turn it back into a useful object
    $user = unserialize($_SESSION['user']);
}

// If we're not a business (or admin) go back to the user redirection page
if( $user->getUserType() != $USERTYPE_BUSINESS && $user->getUserType() != $USERTYPE_ADMIN)
    header("location:login_success.php");

// Connect to our database
include("include/dbconnection.php");


// Search info sent from form
$title = $_POST['title'];
$content = $_POST['content'];
$location = $_POST['location'];
$views = $_POST['viewAmount'];
$preferredindustry = $_POST['preferredIndustry'];


// To protect MySQL injection (more detail about MySQL injection)
$title = stripslashes($title);
$content = stripslashes($content);
$location = stripslashes($location);
$views = stripslashes($views);
$preferredindustry = stripslashes($preferredindustry);

$fixedFee = 0.5;
$price = $fixedFee * $views;
?>
<?php include("include/header.php"); ?>
<body>
  <div id="wrapper">
    <div id="header"> </div>
    <div id="left">
      <div id="logo">
        <h1>Home Sale</h1>
        <p>Only By Owner</p>
      </div>
      <div id="nav">
        <ul>
          <li><a href="login_success.php">Business Index</a></li>
          <li class="important"><a href="addadvertisement.php">Add Advertisement</a></li>
          <li><a href="">View Reports</a></li>
          <li><a href="searchhouse.php">Search House</a></li>
          <li><a href="logout.php">Logout</a></li>
        </ul>
      </div>
      <div id="news">
        <h2>ADVERTISEMENT</h2>
        <p><?php if($location == 1){
            ?><b><?php echo $title?></b>
            <br></br>
            <?php echo $content;?>
            <br></br>
            <?php } ?></p>
        <div class="hr-dots"> </div>

        <p><?php if($location == 2){
            ?><b><?php echo $title?></b>
            <br></br>
            <?php echo $content;?>
            <br></br>
            <?php } ?></p>
        <p class="more"><a href="login_success.php">more</a></p>
      </div>
      <div id="support">
        
      </div>
    </div>
    <div id="right">
      <h2>Add Advertisement</h2>
      <div id="welcome">
          <form action="adconfirmed.php" method="post">
            <input type="hidden" value="<?php echo $title;?>" name="title">
            <input type="hidden" value="<?php echo $content;?>" name="content">
            <input type="hidden" value="<?php echo $views;?>" name="views">
            <input type="hidden" value="<?php echo $location;?>" name="location">
            <b>Title: </b><?php echo $title?>
            <br></br>
            <b>Content:</b>
            <br></br>
            <?php echo $content;?>

            <br></br>
            <b>Preferred Industry: </b><?php echo $preferredindustry?>
            <b>Location:</b>
            <?php switch($location){
        case 1:
        {
          echo "Left 1";
          break;
        }
        case 2:
        {
          echo "Left 2";
          break;
        }
        case 3:
        {
          echo "Bottom Left";
          break;
        }
        case 4:
        {
          echo "Bottom Right";
          break;
        }
		}
        ?>
            <br></br>
            <b>Select number of displays: </b>
            <?php echo $views;?>
            <br></br>
            <p><b>Price: </b><?php echo $price ?></p>
            <br></br>
			      <input type="submit" value="Post" />
            <FORM>
              <INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">
            </FORM>
          </form>
      </div>
      <h3></h3>
      <div id="profile">
        <div id="corp">
          <p><?php if($location == 3){
            ?>
            <b><?php echo $title?></b>
            <br></br>
            <?php echo $content;?>
            <br></br>
            <?php } ?></p>
        </div>
        <div id="indu">
          <p><?php if($location == 4){
            ?><b><?php echo $title?></b>
            <br></br>
            <?php echo $content;?>
            <br></br>
            <?php } ?></p>
        </div>
        <div class="clear"> </div>
      </div>
    </div>
    <div class="clear"> </div>
    <div id="spacer"> </div>
    <div id="footer">
      <div id="copyright">
        &copy; Template taken from http://www.freewebsitetemplates.com/
      </div>
	  <div id="footerline"></div>
    </div>
	
  </div>
</body>
</html>
